import { workType } from "../game/gameType";
import { ccs } from "./services";

export type playerInfo = {
    name: string,
    age: number,
    work: workType,
    income: number, //小时收入
    dayIncome: number,
    money: number,//资产
    monthIncome: number,
    yearIncome: number,
    level: number,
    time: {
        year: number,
        month: number,
        day: number,
    },
    workChance: number,
    maxMonthIncome: number,
    maxYearIncome: number,
}
export class player {
    public wealth: number = 10;
    public work: workType = null;
    public workIndex: number = 0;
    public playerInfo: playerInfo = null;
    

    initPlayer(playerName?: string, age?: number) {
        
        this.playerInfo = {
            name: playerName || "张三",
            age: age || 18,
            dayIncome: 0,
            work: this.work,
            income: 0,
            money: 1000,
            monthIncome: 0,
            yearIncome: 0,
            level: 0,
            time: {
                year: 1,
                month: 1,
                day: 1,
            },
            maxMonthIncome: 0,
            maxYearIncome: 0,
            workChance: 1,
        }
        this.randomWork();
    }
    setWork(work: workType, income?: number){
        this.playerInfo.work = work;
        let workList = ccs.dataMgr.gameJson.workType;
        this.playerInfo.income = workList[this.workIndex].income;
    }
    setPlayerInfo(player: playerInfo) {
        this.playerInfo = player;
    }
    randomWork() {
        let workList = ccs.dataMgr.gameJson.workType;
        this.workIndex = parseInt(Math.random()*5 + "");
        this.setWork(workList[this.workIndex]);
        return workList[this.workIndex].name;
    }
}